

package com.jiantong.user.impl.service;


import com.google.common.base.Throwables;
import com.jiantong.user.impl.dao.GovernmentDao;
import com.jiantong.user.model.Government;
import com.jiantong.user.service.GovernmentWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RpcProvider
public class GovernmentWriteServiceImpl implements GovernmentWriteService {

    private final GovernmentDao governmentDao;
    @Autowired
    public GovernmentWriteServiceImpl(GovernmentDao governmentDao) {
        this.governmentDao = governmentDao;
    }

    @Override
    public Response<Boolean> update(Government government) {
        try {
            return Response.ok(governmentDao.update(government));
        }catch (Exception e){
            log.error("failed to update ", Throwables.getStackTraceAsString(e));
            return Response.fail("update.failed");
        }
    }

    @Override
    public Response<Long> create(Government government) {
        try {
            governmentDao.create(government);
            return Response.ok(government.getId());
        }catch (Exception e){
            log.error("failed to update ", Throwables.getStackTraceAsString(e));
            return Response.fail("update.failed");
        }
    }
}
